#!/bin/bash --login
# loc
backup_path=/Users/zhouzongli/Desktop/db
logfile_path=/Users/zhouzongli/Desktop/db/logs
db_host=127.0.0.1
db_user=root
db_passwd=root
db_database=frontend_local
MYSQLDUMP=/usr/local/mysql/bin/mysqldump

[ ! -d ${backup_path} ] && mkdir -p ${backup_path}
[ ! -d ${logfile_path} ] && mkdir -p ${logfile_path}
execute_date=`date +%Y%m_%d_%H_%M_%S`
logfile=${logfile_path}/${execute_date}.log
backup=${backup_path}/${execute_date}.sql
echo "==============================================" >> ${logfile}
echo "`date "+%F %H:%M:%S"` start backup MySQL record"  >> ${logfile}
cd ${backup_path}
${MYSQLDUMP} -u${db_user} -h $db_host -p${db_passwd} ${db_database} EducationCategory education_feeds Hospital tag source>${backup}
if [ $? -ne 0 ];then
  echo "`date  "+%F %H:%M:%S"` 备份MySQL数据失败"  >> ${logfile}
else
  echo "`date  "+%F %H:%M:%S"` 备份MySQL数据成功,备份文件名:${backup}"  >> ${logfile}
fi
echo "`date "+%F %H:%M:%S"` MySQL数据备份结束"  >> ${logfile}
echo "==============================================" >> ${logfile}
